import { genderStatus, ageStatus, educationStatus, careerStatus } from '@/configs/DefaultStatus/InitStatus';

export const getTextStatus = (props) => {
  return props.status;
};

export const getStringStatus = (props) => {
  if (props && isStringArray(props.status)) {
    return props.status;
  }
};

export function getCurrentStatus(props) {
  return props && props.currentStatus;
}

export function getStringStatusByCurrentStatus(props) {
  return props.status[props.currentStatus];
}

export function getPicTitleDescStatusArr(props) {
  if (props && isPicTitleDescStatusArr(props.status)) {
    return props.status;
  }
}

/**
 * 检查是否为字符串数组
 * @param {Array} status - 待检查的数组
 */
export function isStringArray(status) {
  return Array.isArray(status) && typeof status[0] === 'string';
}

export function isPicTitleDescStatusArr(status) {
  return (
    Array.isArray(status) &&
    typeof status[0] === 'object' &&
    'picTitle' in status[0] &&
    'picDesc' in status[0] &&
    'value' in status[0]
  );
}

export const changeShowStatus = (optionProps, payload) => {
  if (payload !== optionProps.type.currentStatus) {
    optionProps.title.isShow = !optionProps.title.isShow;
    optionProps.desc.isShow = !optionProps.desc.isShow;
    optionProps.position.isShow = !optionProps.position.isShow;
    optionProps.titleSize.isShow = !optionProps.titleSize.isShow;
    optionProps.descSize.isShow = !optionProps.descSize.isShow;
    optionProps.titleWeight.isShow = !optionProps.titleWeight.isShow;
    optionProps.descWeight.isShow = !optionProps.descWeight.isShow;
    optionProps.titleItalic.isShow = !optionProps.titleItalic.isShow;
    optionProps.descItalic.isShow = !optionProps.descItalic.isShow;
    optionProps.titleColor.isShow = !optionProps.titleColor.isShow;
    optionProps.descColor.isShow = !optionProps.descColor.isShow;
  }
};

export const updateInitStatusBeforeAdd = (comStatus, newMaterialName) => {
  switch (newMaterialName) {
    case 'personal-info-name': {
      comStatus.name = 'personal-info-name';
      comStatus.status.title.status = '您的姓名是';
      comStatus.status.type.isShow = false;
      break;
    }
    case 'personal-info-id': {
      comStatus.name = 'personal-info-id';
      comStatus.status.title.status = '请填写身份证号';
      comStatus.status.type.isShow = false;
      break;
    }
    case 'personal-info-tel': {
      comStatus.name = 'personal-info-tel';
      comStatus.status.title.status = '请填写手机号';
      comStatus.status.type.isShow = false;
      break;
    }
    case 'personal-info-wechat': {
      comStatus.name = 'personal-info-wechat';
      comStatus.status.title.status = '请填写微信号';
      comStatus.status.type.isShow = false;
      break;
    }
    case 'personal-info-qq': {
      comStatus.name = 'personal-info-qq';
      comStatus.status.title.status = '请填写QQ号';
      comStatus.status.type.isShow = false;
      break;
    }
    case 'personal-info-email': {
      comStatus.name = 'personal-info-email';
      comStatus.status.title.status = '请填写邮箱';
      comStatus.status.type.isShow = false;
      break;
    }
    case 'personal-info-address': {
      comStatus.name = 'personal-info-address';
      comStatus.status.title.status = '请填写地址';
      comStatus.status.type.isShow = false;
      break;
    }
    case 'personal-info-gender': {
      comStatus.name = 'personal-info-gender';
      comStatus.status.title.status = '您的性别是';
      comStatus.status.options.status = genderStatus();
      break;
    }
    case 'personal-info-age': {
      comStatus.name = 'personal-info-age';
      comStatus.status.title.status = '您的年龄是';
      comStatus.status.options.status = ageStatus();
      break;
    }
    case 'personal-info-education': {
      comStatus.name = 'personal-info-education';
      comStatus.status.title.status = '到目前为止，您的最高学历是';
      comStatus.status.options.status = educationStatus();
      break;
    }
    case 'personal-info-career': {
      comStatus.name = 'personal-info-career';
      comStatus.status.title.status = '您目前的职业是';
      comStatus.status.options.status = careerStatus();
      break;
    }
    case 'personal-info-birth': {
      comStatus.name = 'personal-info-birth';
      comStatus.status.title.status = '请选择出生日期';
      break;
    }
    case 'personal-info-collage': {
      comStatus.name = 'personal-info-collage';
      comStatus.status.title.status = '请填写您的大学';
      comStatus.status.type.isShow = false;
      break;
    }
    case 'personal-info-major': {
      comStatus.name = 'personal-info-major';
      comStatus.status.title.status = '请填写您的专业';
      comStatus.status.type.isShow = false;
      break;
    }
    case 'personal-info-industry': {
      comStatus.name = 'personal-info-industry';
      comStatus.status.title.status = '请填写您的行业';
      comStatus.status.type.isShow = false;
      break;
    }
    case 'personal-info-company': {
      comStatus.name = 'personal-info-company';
      comStatus.status.title.status = '请填写您的公司';
      comStatus.status.type.isShow = false;
      break;
    }
    case 'personal-info-position': {
      comStatus.name = 'personal-info-position';
      comStatus.status.title.status = '请填写您的职位';
      comStatus.status.type.isShow = false;
      break;
    }
  }
};

const SurveyComNameArr = [
  'single-select',
  'multi-select',
  'option-select',
  'single-pic-select',
  'multi-pic-select',
  'text-input',
  'personal-info-name',
  'personal-info-id',
  'personal-info-tel',
  'personal-info-wechat',
  'personal-info-qq',
  'personal-info-email',
  'personal-info-address',
  'personal-info-gender',
  'personal-info-age',
  'personal-info-education',
  'personal-info-career',
  'rate-score',
  'date-time',
  'personal-info-birth',
  'personal-info-collage',
  'personal-info-major',
  'personal-info-industry',
  'personal-info-company',
  'personal-info-position',
];

export function isSurveyComName(value) {
  return SurveyComNameArr.includes(value);
}

// 计算滚动条是否到底部或者顶部
export function handleScroll(event) {
  const target = event.currentTarget;

  // 使用 Math.round() 将值转换为整数
  const scrollTop = Math.round(target.scrollTop);
  const scrollHeight = Math.round(target.scrollHeight);
  const clientHeight = Math.round(target.clientHeight);

  const isAtTop = scrollTop === 0;
  const isAtBottom = scrollHeight - scrollTop === clientHeight;

  if ((isAtTop && event.deltaY < 0) || (isAtBottom && event.deltaY > 0)) {
    event.preventDefault();
    event.stopPropagation();
  }
}
